/**
 * @function 获取系统图片地址
 * @param url
 * @param isBase64
 */
function getSysImgUrl(url: string, isBase64: boolean = false) {
  if (!url) return '';
  if (isBase64) return `data:image/png;base64,${url}`;
  if (url.includes('//') || url.includes('http')) return url;

  return `${process.env.APP_API_URL}storage/${url}`;
}

/**
 * @function 测试环境打印日志
 */
function logInDev(args: any) {
  if (['local', 'development'].includes(process.env.APP_ENV as string)) window.console.log(args);
}

/**
 * @function 判断是否移动端
 */
function isMobile() {
  return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
}

/**
 * @function 判断是否完整域名
 */
function isFullDomainName(url: string): boolean {
  if (!url) return false;
  return /[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+\.?/i.test(url);
}

export { getSysImgUrl, logInDev, isMobile, isFullDomainName };
